package de.karlNet.sambamanager.view.beans.forms;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapController.DnsTree;
import de.karlNet.sambamanager.ldapController.commands.CreateARecord;
import de.karlNet.sambamanager.ldapModel.dns.LdapDNSARecord;
import de.karlNet.sambamanager.view.beans.trees.SelectedNodeContainer;

@Controller
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class CreateARecordBean extends ViewBean {
	@Autowired
	private CreateARecord createARecord;
	@Autowired
	private DnsTree dnsTree;

	protected LdapDNSARecord aRecord = new LdapDNSARecord();

	public LdapDNSARecord getaRecord() {
		return aRecord;
	}

	public void setaRecord(LdapDNSARecord aRecord) {
		this.aRecord = aRecord;
	}

	@Autowired
	protected SelectedNodeContainer nodeContainer;

	public String create() {
		try {
			this.aRecord.setDn("dc=" + this.aRecord.getCn() + ","
					+ nodeContainer.selectedNode.getLdapObject().getDn());
			this.createARecord.createARecordItself(this.aRecord);
			this.dnsTree.reset();
			this.aRecord = new LdapDNSARecord();
			this.setShow(false);
			return "index.xhtml";
		} catch (Exception e) {
			this.showErrorMessage(e.getMessage());
			return "";
		}
	}

	@Override
	public String getPageName() {
		return "createARecordView";
	}
}
